<template>
  <div>
    <el-card class="box-card">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="值班医生">
          <template>
            <el-select v-model="form.docid" placeholder="请选择">
              <el-option
                      v-for="item in doctors"
                      :key="item.docId"
                      :label="item.realName"
                      :value="item.docId">
              </el-option>
            </el-select>
          </template>
        </el-form-item>
        <el-form-item label="值班日期">
          <el-date-picker
                  v-model="form.dutyday"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  :picker-options="{
                        format: 'yyyy-MM-dd HH:mm:ss'
                      }"
                  placeholder="值班日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  import { edit, findById } from '@/network/duty'
  import {findDoctor} from '@/network/doctor'

  export default {
    name: 'DutyEdit',
    created() {
      this.getUser()
      this.findDoctor()
    },
    methods: {
      getUser() {
        findById(window.sessionStorage.getItem("ddid")).then(res => {
          console.log(res)
          this.form = res.data.data
        })
      },
      onSubmit() {
        edit(this.form).then(res => {
          this.$router.back(1)
        })
      },
      cancel() {
        this.$router.back(1)
      },
      findDoctor() {
        findDoctor().then(res => {
          console.log(res.data.data.records)
          this.doctors = res.data.data.records
        })
      },
    },
    data() {
      return {
        form: {
        },
        doctors: []
      }
    }
  }
</script>

<style scoped>

</style>
